package com.yhty.dao;

import java.sql.ResultSet;
import java.sql.SQLException;

import javax.annotation.Resource;

import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Repository;

import com.yhty.model.WeDefine;

/**
 * 水电统一单价数据类
 * @author RoySong
 * 2011-3-31-下午07:25:47
 */
@Repository("weDefineDao")
public class WeDefineDao {

	private JdbcTemplate jdbcTemplate;

	@Resource(name="jdbcTemplate")
	public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
		this.jdbcTemplate = jdbcTemplate;
	}
	
	/**
	 * 更新水电统一单价
	 * @param wd
	 */
	public void update(WeDefine wd){
		String sql = "update wedefine set water_price="+
		wd.getWater_price()+",electric_price="+
		wd.getElectric_price();
		jdbcTemplate.update(sql);
	}
	
	/**
	 * 获取水电统一单价
	 * @return
	 */
	public WeDefine get(){
		String sql = "select * from wedefine";
		return jdbcTemplate.queryForObject(sql,new RowMapper<WeDefine>(){

			public WeDefine mapRow(ResultSet rs, int rowNum)
					throws SQLException {
				WeDefine wd = new WeDefine();
				wd.setWater_price(rs.getFloat("water_price"));
				wd.setElectric_price(rs.getFloat("electric_price"));
				return wd;
			}
			
		});
	}
}
